﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StudentInfoSystem.Logic
{
    class Validation
    {
        public static bool ValidateUsername(string username)
        {
            bool isUsernameValid = true;
            if (username.Length > 3)
            {
                foreach (char symbol in username)
                {
                    if (!Char.IsLetter(symbol) && !Char.IsNumber(symbol))
                    {
                        isUsernameValid = false;
                    }
                }
            }
            else
            {
                isUsernameValid = false;
            }
            return isUsernameValid;
        }

        public static bool ValidatePassword(string password)
        {
            bool isPasswordValid = true;
            if (password.Length < 3 || password.Length > 30)
            {
                isPasswordValid = false;
            }
            return isPasswordValid;
        }

        public static bool ValidateGivenUser(string username, string password)
        {
            bool isUserValid = false;
            var user = Data.UserDataAccess.GetUser(username);
            if (user != null && user.Password == password)
            {
                isUserValid = true;
            }
            return isUserValid;
        }
    }
}
